
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Redis淘汰机制 - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>Redis淘汰机制 - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">Redis中的淘汰机制旨在解决什么核心问题？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Redis的淘汰机制是为了在内存不足时，有效管理数据的过期与淘汰，以保障系统的稳定性。其目标是确保缓存中存放的数据都是热数据，并及时清理冷数据以释放内存空间。</div>
          </div>
          <div class="card-source">来源: 文档开篇及结尾部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">LRU（最近最少使用）算法是如何判断并淘汰数据的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">LRU算法是一种基于使用频率的淘汰机制。当内存不足时，Redis通过记录键的访问时间来判断哪些键最久未被使用，然后将这些最近最少使用的数据淘汰掉。</div>
          </div>
          <div class="card-source">来源: LRU(最近最少使用)</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">LFU（最不经常使用）算法的淘汰依据是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">LFU算法是一种基于使用频率的淘汰机制。它通过一个计数器来记录每个键的使用次数，并在需要淘汰数据时，选择使用频率最低的键进行淘汰。</div>
          </div>
          <div class="card-source">来源: LFU(最不经常使用)</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">策略</div>
          <div class="card-question">当Redis采用默认的`noeviction`策略且内存已满时，它会如何响应读写请求？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">策略</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">在内存超过阈值后，Redis不做任何清理工作。它会对所有写操作返回错误，但是对读请求会正常处理。</div>
          </div>
          <div class="card-source">来源: noeviction</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">TTL（生存时间）机制是如何工作的，它适用于哪种场景？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Redis允许为每个键设置过期时间（即TTL）。一旦键的生存时间到期，系统就会自动将其淘汰。这种方式适用于需要在一定时间内保留的临时数据，如缓存。</div>
          </div>
          <div class="card-source">来源: TTL (生存时间)</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">策略</div>
          <div class="card-question">请解释 `volatile-lru` 和 `allkeys-lru` 这两种淘汰策略的主要区别。</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">策略</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">主要区别在于淘汰范围不同。`volatile-lru` 只在设置了生存时间的键中淘汰最近最少使用的键，而 `allkeys-lru` 则会在全部的键中进行筛选并淘汰最近最少使用的键。</div>
          </div>
          <div class="card-source">来源: noeviction 章节下的策略列表</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">什么是“定期删除”机制？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">定期删除是一种系统定期检查键的过期时间，并删除已过期键的淘汰机制。这种方式虽然不够智能，但可以在一定程度上释放内存。</div>
          </div>
          <div class="card-source">来源: 定期删除</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">策略</div>
          <div class="card-question">随机淘汰策略是如何选择要删除的键的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">策略</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">随机淘汰是一种简单的淘汰策略，系统会随机选择一个键进行淘汰。它不考虑键的使用频率或过期时间。</div>
          </div>
          <div class="card-source">来源: 随机淘汰</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">策略</div>
          <div class="card-question">在内存不足时，`volatile-ttl` 策略会如何操作？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">策略</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">当内存不足时，`volatile-ttl` 策略会在设置了生存时间的键中，找出并淘汰一个剩余生存时间最短的键。</div>
          </div>
          <div class="card-source">来源: noeviction 章节下的策略列表</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
